package com.example.cd5160866.materialdesgin;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.example.cd5160866.materialdesgin.capture.CaptureDialog;
import com.example.cd5160866.materialdesgin.capture.CaptureViewDecorate;
import com.example.cd5160866.materialdesgin.capture.DecorateViewClickListener;

/**
 * Created by cd5160866 on 2018/1/19.
 */

public class CaptureDemoActivity extends Activity {
    TextView tvWallet;
    TextView tvName;
    ImageView image;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_guide);
        tvWallet = (TextView) findViewById(R.id.tv_wallet);
        tvName = (TextView) findViewById(R.id.tv_name);
        image = (ImageView) findViewById(R.id.image);
        tvWallet.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startGuide();
            }
        });
        image.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivity(new Intent(CaptureDemoActivity.this, CaptureViewActivity.class));
            }
        });
    }

    private void startGuide() {

        //第一步 构建dialog 让钱包布局高亮 并且加入自定义view 修饰
        new CaptureDialog.Builder(this)
                .setCancelableBackPressed(false)
                .setOnShadowClickListener(null)//屏蔽掉默认让dialog dismiss的点击事件
                .create()
                .addCaptureView(tvWallet, new CaptureViewDecorate(View.inflate(this, R.layout.view_i_know_step1, null), new DecorateViewClickListener() {
                    @Override
                    public void decorateViewClick(CaptureDialog dialog) {
                        //第一步结束 进入第二部 继续操作dialog
                        dialog.clear();
                        CaptureViewDecorate captureViewDecorateStep2 = new CaptureViewDecorate(32, 20, getResources().getDrawable(R.drawable.circle_red),
                                View.inflate(CaptureDemoActivity.this, R.layout.view_i_know_step2, null),
                                new DecorateViewClickListener() {
                                    @Override
                                    public void decorateViewClick(final CaptureDialog dialog) {
                                        //第二步结束 进入第三部 继续操作dialog
                                        dialog.clear();
                                        CaptureViewDecorate captureViewDecorateStep3 = new CaptureViewDecorate(View.inflate(CaptureDemoActivity.this, R.layout.view_i_know_step3, null),
                                                new DecorateViewClickListener() {
                                                    @Override
                                                    public void decorateViewClick(CaptureDialog dialog) {
                                                        dialog.dismiss();
                                                        Toast.makeText(CaptureDemoActivity.this, "引导完成", Toast.LENGTH_SHORT).show();
                                                    }
                                                }, 0, 300);
                                        dialog.addCaptureView(image, captureViewDecorateStep3);
                                    }
                                }, 40, 400);
                        dialog.addCaptureView(tvName, captureViewDecorateStep2);
                    }
                }, 300, -600)).showCapture();
    }
}
